﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dados.DigitalTVDSTableAdapters;

namespace Dados
{
    class ProgramacaoSQL:IProgramacaoBD
    {
        #region IProgramacaoBD Members

        public int Inserir(ProgramacaoVO programacaovo)
        {
            T_ProgramacaoTableAdapter prog = new T_ProgramacaoTableAdapter();
            return prog.Insert(programacaovo.IdCanal, programacaovo.IdEpisodio, programacaovo.DataHora);
        }

        public int Excluir(ProgramacaoVO programacaovo)
        {
            T_ProgramacaoTableAdapter prog = new T_ProgramacaoTableAdapter();
            return prog.Delete(programacaovo.Id_programacao);
        }

        public ProgramacaoVO Consultar(ProgramacaoVO programacaovo)
        {
            ProgramacaoVO progvo = new ProgramacaoVO(); 
            T_ProgramacaoTableAdapter prog = new T_ProgramacaoTableAdapter();
            DigitalTVDS.T_ProgramacaoDataTable digitv = prog.GetProgramacaoPorId(programacaovo.Id_programacao);
            progvo.Id_programacao = digitv[0].id_programacao;
            progvo.IdCanal = digitv[0].nr_canal;
            progvo.IdEpisodio = digitv[0].nr_episodio;
            return progvo;
        }

        public List<ProgramacaoVO> ConsultarLista(ProgramacaoVO programacaovo)
        {
            T_ProgramacaoTableAdapter prog = new T_ProgramacaoTableAdapter();
            DigitalTVDS.T_ProgramacaoDataTable digitv = prog.GetProgramacaoPorId(programacaovo.Id_programacao);
            List<ProgramacaoVO> lista = new List<ProgramacaoVO>();
            foreach (DigitalTVDS.T_ProgramacaoRow linha in digitv)
            {
                ProgramacaoVO progvo = new ProgramacaoVO();
                progvo.Id_programacao = linha.id_programacao;
                lista.Add(progvo);
            }
            return lista;
        }
        #endregion
    }
}
